<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP 5
 *
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 */

App::uses('Controller', 'Controller');
/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package		app.Controller
 * @link		http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */
class AppController extends Controller {
	public $helpers = array('Html', 'Form', 'Js', 'Session');
	public $components = array('Auth','Session','Email', 'RequestHandler', 'Cookie');
	public $uses = array('Brand');
	
	public function beforeFilter() {

			$this->Auth->authenticate = array(
				'Form' => array(
					'fields' => array('username' => 'email','password' => 'password')
				)
			);
		$this->Auth->logoutRedirect = '/';
		$this->Auth->allow(array('login'));
		//$this->Auth->allow();
	}

	public function beforeRender() {
		$this->set('user', $this->Auth->user()); 
        $userId =  $this->Auth->user('id');
		$this->set('brands', $this->Brand->getMyBrands($userId));
		//$this->set('brands', $this->Brand->getMyBrands());
	}

	public function isAuthorized($user = null) {
		return true;
	}
	
	/*public function appError($error) {
		$this->redirect('/');
	}*/
}
